﻿using DimensionsHelper.Common.Contracts.DataCollector;

namespace DimensionsHelper.Client.ViewModels.DataCollector;

public class IndexFileListViewModel(IServiceProvider serviceProvider) :
    ObservableCollection<IndexFileViewModel>
{
    private IndexFileViewModel? _currentFile;


    public IRelayCommand AddNewEmptyFileCommand => new RelayCommand(AddNewEmptyFile);


    public IndexFileViewModel? CurrentFile
    {
        get => _currentFile;
        set
        {
            if (Equals(_currentFile, value))
            {
                return;
            }

            _currentFile = value;
            OnPropertyChanged(new PropertyChangedEventArgs(nameof(CurrentFile)));
        }
    }

    private void AddNewEmptyFile()
    {
        IndexFileViewModel? file = serviceProvider.GetRequiredService<IndexFileViewModel>();
        Add(file);
    }


    public List<CollectorInputFile> ToInputFiles()
    {
        List<CollectorInputFile>? list = new();

        foreach (IndexFileViewModel? item in this)
        {
            item.ToInputFiles(list);
        }

        return list;
    }
}